package com.honsen.yangban;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.honsen.yangban.utils.DialogUtils;
import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.PermissionListener;

import java.util.List;

public class MainActivity extends AppCompatActivity {

    private LollipopFixedWebView web;
    private TextView rippleButton;
    private TextView tv_clone;
    private TextView rippleButton2;
    private int mSecretNumber = 0;
    private static final long MIN_CLICK_INTERVAL = 600;
    private long mLastClickTime;
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 11:
                    rippleButton.animate().scaleX(1).scaleY(1).setDuration(100).start();
                    Intent intent = new Intent(MainActivity.this, WebViewActivity.class);
                    startActivity(intent);
                    break;
                case 22:
                    rippleButton2.animate().scaleX(1).scaleY(1).setDuration(100).start();
                    Intent intent1 = new Intent(MainActivity.this, VideoActivity.class);
                    startActivity(intent1);
                    break;

                default:
                    break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        AndPermission.with(this).permission( Manifest.permission.ACCESS_NETWORK_STATE,Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .requestCode(0).callback(new PermissionListener() {
            @Override
            public void onSucceed(int requestCode, @NonNull List<String> grantPermissions) {
            }
            @Override
            public void onFailed(int requestCode, @NonNull List<String> deniedPermissions) {
            }
        }).start();




        rippleButton = findViewById(R.id.rb_1);
        tv_clone = findViewById(R.id.tv_clone);
        rippleButton2 = findViewById(R.id.rb_2);
        tv_clone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                long currentClickTime = SystemClock.uptimeMillis();
                long elapsedTime = currentClickTime - mLastClickTime;
                mLastClickTime = currentClickTime;

                if (elapsedTime < MIN_CLICK_INTERVAL) {
                    ++mSecretNumber;
                    if (3 == mSecretNumber) {
                        DialogUtils.dialogTipCancel("关闭应用", MainActivity.this, new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                MainActivity.this.finish();
                            }
                        });
                    }
                } else {
                    mSecretNumber = 0;
                }
            }
        });
        rippleButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rippleButton.animate().scaleX(0.8f).scaleY(0.8f).setDuration(200).start();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        Message msg = new Message();
                        msg.what = 11;
                        handler.sendMessage(msg);
                    }
                }, 500);

            }
        });
        rippleButton2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                rippleButton2.animate().scaleX(0.8f).scaleY(0.8f).setDuration(200).start();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        Message msg = new Message();
                        msg.what = 22;
                        handler.sendMessage(msg);
                    }
                }, 500);

            }
        });

    }

}
